from django import template

register = template.Library()

@register.filter('spacify_code')
def spacify_code(value):
  """
  A custom django template filter written to replaces all spaces inside
  an html tag inside value with &nbsp;
  Useful for <code> tags in problem.description for PyKata

  Args:
    value: data passed by django template to this filter
    tag_name: the html tag present inside value which needs to be
      processed

  Returns: value with spaces inside the tag replaced by &nbsp;

  Raises: no exceptions as of now
  """
  try:
    value = value.replace ('&lt;code&gt;', '<code>').replace('&lt;/code&gt;', '</code>').replace (' ','&nbsp;')
    return value
  except:
    return value

